import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p002 from './p002';
import p003 from './p003';
export default async function a007(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 点击我发出的的查寻按钮是触发
	const a1 = get('staff_no');
	const inform_title1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="inform_title1"]').value;
	// 时间
	const receive_time1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="receive_time1"]').value;
	const receive_time_end1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="receive_time_end1"]').value;
	let receive_time2 = 10000;
	if (receive_time1 !== "") {
		receive_time2 = new Date(receive_time1).getTime();
	}
	let receive_time_end2 = 10000000000000000000000000000;
	if (receive_time_end1 !== "") {
		receive_time_end2 = new Date(receive_time_end1).getTime();
	}
	const res1 = await nodejs<{
		res: Array<{
			inform_no: string, inform_title: string, inform_content: string,
			notification_time: number, pub_user_no: string, pub_user_name: string
		}>; res1: number
	}>('notification-notice/zj-000001/s007',
		{
			filter: {
				pn: 1, a: a1,
				inform_title: inform_title1,
				receive_time: receive_time2,
				receive_time_end: receive_time_end2
			}
		});
	const arr1 = Array();
	const num = res1.res1[0].inform_title;
	for (let i = 0; i < num; i++) {
		arr1.push(res1.res[i].inform_no);
	}
	const newres1 = res1.res.map((n) => {
		return { ...n, receive_time: format(n.notification_time, 2) };
	});
		const arr3 = Array();
		for (let i = 0; i < arr1.length; i++) {
	const res3 = await nodejs<{ dt: Array<{ inform_no: string, pub_user_no: string, pub_user_name: string }> }>('notification-notice/zj-000001/s006',
				{
					filter: {
						arr: arr1[i]
					}
				});
			arr3.push(res3.dt);
		}
		const arr5 = Array();
		for (let i = 0; i < arr3.length; i++) {
			let strName = "";
			for (let j = 0; j < arr3[i].length; j++) {
				if (arr3[i].length === 0) {
					strName = "";
				}
				if (arr3[i].length === 1) {
					strName += arr3[i][j].pub_user_name;
				}
				if (arr3[i].length === 2) {
					if (j === 1) {
						strName += arr3[i][j].pub_user_name;
					} else {
						strName += arr3[i][j].pub_user_name + ",";
					}
				}
				if (arr3[i].length === 3) {
					if (j === 3) {
						strName += arr3[i][j].pub_user_name;
					} else {
						strName += arr3[i][j].pub_user_name + ",";
					}
				}
				if (arr3[i].length > 3) {
					if (j === 3) {
						strName += arr3[i][j].pub_user_name + "...";
					}
					if (j < 3) {
						strName += arr3[i][j].pub_user_name + ",";
					}
				}
			}
			arr5.push(strName);
		}
		let a = 0;
		const newarr = newres1.map((n) => {
			n.pub_user_name = arr5[a];
			a++;
			return n;
		});
	const dtPn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	dtPn.style.display = 'none';
	if (newarr.length > 0) {
		render(fd, newarr, p002, "p002", "inner");
	} else {
		render(fd, "", p003, 'p003', 'inner');
	}

}
